CLASS lsc_zr_ymoont_0010 DEFINITION INHERITING FROM cl_abap_behavior_saver.

  PROTECTED SECTION.

    METHODS save_modified REDEFINITION.

ENDCLASS.

CLASS lsc_zr_ymoont_0010 IMPLEMENTATION.

  METHOD save_modified.
    DATA lt_create TYPE STANDARD TABLE OF ymoont_0010.

    DATA: purchase_requisitions      TYPE TABLE FOR CREATE i_purchaserequisitiontp,
          purchase_requisition       TYPE STRUCTURE FOR CREATE i_purchaserequisitiontp,
          purchase_requisition_items TYPE TABLE FOR CREATE i_purchaserequisitiontp\_purchaserequisitionitem,
          purchase_requisition_item  TYPE STRUCTURE FOR CREATE i_purchaserequisitiontp\\purchaserequisition\_purchaserequisitionitem.

    DATA n TYPE i.

    IF create IS NOT INITIAL.



*    MOVE-CORRESPONDING create-zr_ymoont_0010 to lt_create.
*
*    insert ymoont_0010 from TABLE @lt_create.

      DATA: lt_pr_create   TYPE TABLE FOR CREATE i_purchaserequisitiontp,
            lt_pri_create  TYPE TABLE FOR CREATE i_purchaserequisitiontp\_purchaserequisitionitem,
            lt_pram_create TYPE TABLE FOR CREATE i_purchasereqnitemtp\_purchasereqnacctassgmt,
            lt_prit_create TYPE TABLE FOR CREATE i_purchasereqnitemtp\_purchasereqnitemtext.

      lt_pr_create      =  VALUE #(  ( %cid                    = 'My%CID_1'
                                       purchaserequisitiontype = 'NB' ) ).
      lt_pri_create     =  VALUE #(  ( %cid_ref                = 'My%CID_1'
                                       %target = VALUE #(  (
                                               %cid                            = 'My%ItemCID_1'
                                               plant                           = '4310'
                                               purchaserequisitionitemtext     = 'ASUG2022'
                                               accountassignmentcategory       = 'U'
                                               requestedquantity               = '8.00'
                                               baseunit                        = 'KG'
                                               purchaserequisitionprice        = '10.00'
                                               purreqnitemcurrency             = 'EUR'
                                               materialgroup                   = 'A001'
                                               purchasinggroup                 = '001'
                                               purchasingorganization          = '1010'
                                               material                        = '000000000000000004'
                                                       )  )
                                  )  ).
      lt_pram_create    =  VALUE #( (  %cid_ref               = 'My%ItemCID_1'
                                       %target = VALUE #( (
                                              %cid                            = 'My%AccntCID_1'
                                              costcenter                      = 'JMW-COST'
                                              glaccount                       = '0000400000' ) ) ) ).
      lt_prit_create    =  VALUE #( (  %cid_ref               = 'My%ItemCID_1'
                                       %target = VALUE #( (
                                              %cid                            = 'My%TextCID_1'
                                              textobjecttype                  = 'B01'
                                              language                        = 'E'
                                              plainlongtext                   = 'item text created from PAAS API'
                                                          )

                                                          (
                                              %cid             = 'My%TextCID_2'
                                              textobjecttype                  = 'B02'
                                              language                        = 'E'
                                              plainlongtext                   = 'item2 text created from PAAS API'
                                            ) )
                                   )  ).

      MODIFY ENTITIES OF i_purchaserequisitiontp
    ENTITY purchaserequisition CREATE FIELDS ( purchaserequisitiontype ) WITH lt_pr_create

    CREATE BY \_purchaserequisitionitem
    FIELDS (    plant
*                purchaserequisitionitemtext
*                accountassignmentcategory
                requestedquantity
                baseunit
*                purchaserequisitionprice
*                purreqnitemcurrency
*                materialgroup
*                purchasinggroup
*                purchasingorganization
*                multipleacctassgmtdistribution
                material
            )

    WITH lt_pri_create "ENTITY purchaserequisitionitem
*    CREATE BY \_purchasereqnacctassgmt
*    FIELDS (    costcenter
*                glaccount
*                quantity
*                baseunit
*            )
*    WITH lt_pram_create CREATE BY \_purchasereqnitemtext FIELDS ( plainlongtext ) WITH lt_prit_create
    REPORTED DATA(ls_pr_reported)
    MAPPED DATA(ls_pr_mapped)
    FAILED DATA(ls_pr_failed).

    ENDIF.
  ENDMETHOD.

ENDCLASS.

CLASS lhc_zr_ymoont_0010 DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.
    METHODS:
      get_global_authorizations FOR GLOBAL AUTHORIZATION
        IMPORTING
        REQUEST requested_authorizations FOR zr_ymoont_0010
        RESULT result,
      create_pr FOR MODIFY
            IMPORTING keys FOR ACTION zr_ymoont_0010~create_pr RESULT result.
ENDCLASS.

CLASS lhc_zr_ymoont_0010 IMPLEMENTATION.
  METHOD get_global_authorizations.
  ENDMETHOD.
  METHOD create_pr.

      DATA: lt_pr_create   TYPE TABLE FOR CREATE i_purchaserequisitiontp,
            lt_pri_create  TYPE TABLE FOR CREATE i_purchaserequisitiontp\_purchaserequisitionitem,
            lt_pram_create TYPE TABLE FOR CREATE i_purchasereqnitemtp\_purchasereqnacctassgmt,
            lt_prit_create TYPE TABLE FOR CREATE i_purchasereqnitemtp\_purchasereqnitemtext.

      lt_pr_create      =  VALUE #(  ( %cid                    = 'My%CID_1'
                                       purchaserequisitiontype = 'NB' ) ).
      lt_pri_create     =  VALUE #(  ( %cid_ref                = 'My%CID_1'
                                       %target = VALUE #(  (
                                               %cid                            = 'My%ItemCID_1'
                                               plant                           = '4310'
                                               purchaserequisitionitemtext     = 'ASUG2022'
                                               accountassignmentcategory       = 'U'
                                               requestedquantity               = '8.00'
                                               baseunit                        = 'KG'
                                               purchaserequisitionprice        = '10.00'
                                               purreqnitemcurrency             = 'EUR'
                                               materialgroup                   = 'A001'
                                               purchasinggroup                 = '001'
                                               purchasingorganization          = '1010'
                                               material                        = '000000000000000004'
                                                       )  )
                                  )  ).
      lt_pram_create    =  VALUE #( (  %cid_ref               = 'My%ItemCID_1'
                                       %target = VALUE #( (
                                              %cid                            = 'My%AccntCID_1'
                                              costcenter                      = 'JMW-COST'
                                              glaccount                       = '0000400000' ) ) ) ).
      lt_prit_create    =  VALUE #( (  %cid_ref               = 'My%ItemCID_1'
                                       %target = VALUE #( (
                                              %cid                            = 'My%TextCID_1'
                                              textobjecttype                  = 'B01'
                                              language                        = 'E'
                                              plainlongtext                   = 'item text created from PAAS API'
                                                          )

                                                          (
                                              %cid             = 'My%TextCID_2'
                                              textobjecttype                  = 'B02'
                                              language                        = 'E'
                                              plainlongtext                   = 'item2 text created from PAAS API'
                                            ) )
                                   )  ).

      MODIFY ENTITIES OF i_purchaserequisitiontp
    ENTITY purchaserequisition CREATE FIELDS ( purchaserequisitiontype ) WITH lt_pr_create

    CREATE BY \_purchaserequisitionitem
    FIELDS (    plant
*                purchaserequisitionitemtext
*                accountassignmentcategory
                requestedquantity
                baseunit
*                purchaserequisitionprice
*                purreqnitemcurrency
*                materialgroup
*                purchasinggroup
*                purchasingorganization
*                multipleacctassgmtdistribution
                material
            )

    WITH lt_pri_create "ENTITY purchaserequisitionitem
*    CREATE BY \_purchasereqnacctassgmt
*    FIELDS (    costcenter
*                glaccount
*                quantity
*                baseunit
*            )
*    WITH lt_pram_create CREATE BY \_purchasereqnitemtext FIELDS ( plainlongtext ) WITH lt_prit_create
    REPORTED DATA(ls_pr_reported)
    MAPPED DATA(ls_pr_mapped)
    FAILED DATA(ls_pr_failed).

  ENDMETHOD.

ENDCLASS.
